package com.example.controller.customer;

import com.example.dto.StorePageQueryDTO;
import com.example.entity.Store;
import com.example.mapper.StoreDao;
import com.example.result.PageResult;
import com.example.result.Result;
import com.example.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年03月21日 23:04
 */
@RestController("customerStoreController")
@RequestMapping("/customer/store")
@Slf4j
@Api(tags = "C端-商店接口")
public class StoreController {

    private final String SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    private StoreDao storeDao;

    @Autowired
    private StoreService storeService;

    @ApiOperation("设置店铺营业状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status,Long storeId){
        log.info("设置店铺营业状态为：{}",status==1?"营业中":"打烊中");
        storeDao.setStatus(status,storeId);
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus(Long storeId){
        Integer status = storeDao.getStatus(storeId);
        log.info("设置店铺营业状态为：{}",status==1?"营业中":"打烊中");
        return Result.success(status);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询店铺")
    public Result<Store> queryById(@PathVariable Long id){
        log.info("查询店铺：{}",id);
        return Result.success(storeService.queryById(id));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询商店")
    public Result<PageResult> page(StorePageQueryDTO storePageQueryDTO){
        log.info("查询店铺：{}",storePageQueryDTO);
        PageResult pageResult = storeService.page(storePageQueryDTO);
        return Result.success(pageResult);
    }
}
